﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CUCTV
{
    public partial class PopUp : Form
    {
        private const int WIDTH = 317;
        private const int HEIGHT = 213;
        //停留时间
        public const int StayTime = 5000;
               
        public PopUp()
        {
            this.SetStyle(ControlStyles.DoubleBuffer |
             ControlStyles.UserPaint |
             ControlStyles.AllPaintingInWmPaint,
             true);
            this.UpdateStyles();   
  
            InitializeComponent();
           // SetLocation();
        }

        protected override void OnLoad(EventArgs e)
        {
          //  base.OnLoad(e);
            Screen[] screens = Screen.AllScreens;
            //获取屏幕变量
            Screen screen = screens[0];
            int offsetY = 34;
            //WorkingArea为Windows桌面的工作区
            this.Location = new Point(screen.WorkingArea.Width - WIDTH, screen.WorkingArea.Height - offsetY);
            this.timer2.Interval = StayTime;
           
        }

      

        private void timer1_Tick(object sender, System.EventArgs e)
        {
            ScrollUp();
        }

        private void timer2_Tick(object sender, System.EventArgs e)
        {
            timer2.Enabled = false;
            timer3.Enabled = true;
        }

        private void timer3_Tick(object sender, System.EventArgs e)
        {
            ScrollDown();
        }

        public void ScrollShow()
        {
                       
            this.Width = WIDTH;
            this.Height = 0;           
            this.timer1.Enabled = true;
            this.Show();
        }

        private void ScrollUp()
        {
            if (Height < HEIGHT)
            {
                this.Height += 3;
                this.Location = new Point(this.Location.X, this.Location.Y - 3);
            }
            else
            {
                this.timer1.Enabled = false;
                this.timer2.Enabled = true;
            }
        }

        private void ScrollDown()
        {
            if (Height >= 3)
            {
                this.Height -= 3;
                this.Location = new Point(this.Location.X, this.Location.Y + 3);
            }
            else
            {
                this.Visible = false;
                this.timer3.Enabled = false;
                this.Close();
            }
        }
    }
}
